package cn.itcast.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.itcast.dao.ChapterDao;
import cn.itcast.mapper.ChapterMapper;
import cn.itcast.util.MybatisUtil;
import cn.itcast.vo.Chapter;


public class ChapterDaoImpl implements ChapterDao{
	private SqlSessionFactory sqlSessionFactory;

	public ChapterDaoImpl() {
	   sqlSessionFactory=MybatisUtil.getSqlSessionFactory();
	   System.out.println("SqlSessionFactory工厂:"+sqlSessionFactory.toString());
	}
	@Override
	public List<Chapter> getChapterByTextBookId(int id) {
		
		List<Chapter> list = null;
		SqlSession sqlSession = sqlSessionFactory.openSession();
		ChapterMapper chapterMapper=sqlSession.getMapper(ChapterMapper.class);
		list=chapterMapper.getChapterByTextBookId(id);
		System.out.println("list:"+list);
		System.out.println("size:"+list.size());
		sqlSession.close();
		
		return list;
	}
	
	

}
